package isquirrel.beans;

import isquirrel.semantic.DBpedia;
import isquirrel.util.URL;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Recommendation {
	String url;
	String pageTitle;
	String thumbnailURL = null;
	String website = null;
	String _abstract = null;
	

	public Recommendation(String url, boolean getAbstract) throws UnsupportedEncodingException {
		DBpedia d = new DBpedia();
		this.url = url;
		if (getAbstract){
			d.fillRecommendation(this);
		}
		this.pageTitle = URLDecoder.decode(URL.getTitle(url), "UTF-8");
	}

	public String getAbstract() {
		if (_abstract == null) return "No description found.";
		return _abstract;
	}
	
	public String getAbstract_short(int wordCount) {
		
		if (_abstract == null) return "No description found.";

		String abstr = "";
		String[] words = _abstract.split(" ");
		
		int i = 0;
		String end = "";
		for (String word: words){
			if (i == wordCount) {end = "...";break;}
			abstr += word + " ";
			if (abstr.length() > 450) {end = "..."; break; } 
			++i;
		}
		
		return abstr.trim() + end;
	}

	public void setAbstract(String abstract1) {
		_abstract = abstract1;
	}
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getPageTitle() {
		return pageTitle;
	}

	public void setPageTitle(String pageTitle) {
		this.pageTitle = pageTitle;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}	
}
